﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MongoDB.Driver;
using System.Configuration;

namespace IFTRUE.EIMS.BLL
{
    /// <summary>
    /// 作用：MongoDB工厂类
    /// 作者：iftrue
    /// 日期：2013-08-19
    /// </summary>
    public class MongoDbFactory
    {
        private static MongoDatabase _mongoDatabase;

        public static MongoDatabase MongoDatabase
        {
            get { return MongoDbFactory.GetMongoDatabase(); }
        }

        /// <summary>
        /// 获取MongoDB数据库连接
        /// </summary>
        /// <returns></returns>
        public static MongoDB.Driver.MongoDatabase GetMongoDatabase()
        {
            return MongoDbFactory.GetMongoDatabase(ConfigurationManager.AppSettings["mongodbconn"], ConfigurationManager.AppSettings["mongodbname"]);
        }

        /// <summary>
        /// 获取MongoDB数据库连接
        /// </summary>
        /// <param name="conn"></param>
        /// <returns></returns>
        public static MongoDB.Driver.MongoDatabase GetMongoDatabase(string conn, string dbname)
        {
            //创建数据库链接
            MongoServer server = new MongoClient().GetServer();
            //获得数据库test
            MongoDatabase db = server.GetDatabase(dbname);
            return db;
        }
    }
}